package com.wink_172.library.view

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import android.widget.Toast
import com.wink_172.library.R

 object CustomToast {

    @JvmStatic
    fun showToast(context: Context, message: String?) {
        val root = LayoutInflater.from(context).inflate(R.layout.custom_toast, null)
        val textView = root.findViewById<View>(R.id.text_view) as TextView
        textView.text = message
        var toastStart = Toast(context)
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val height = wm.defaultDisplay.height
        //Toast的Y坐标是屏幕高度的1/3，不会出现不适配的问题
        toastStart?.let {
            toastStart->
            toastStart.setGravity(Gravity.CENTER, 0, 0)
            toastStart.duration = Toast.LENGTH_SHORT
            toastStart.view = root
            toastStart.show()
        }

    }
}